package com.atguigu.gmall.user.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.user.model.UserInfo;
import com.atguigu.gmall.user.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author: 小兰
 * @Date: 2023/5/4 19:22
 */
@RestController
@RequestMapping("/api/user")
public class PassportController {
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 用户登录
     * @param userInfo
     * @param httpServletRequest
     * @return
     */
    @PostMapping("/passport/login")
    public Result login(@RequestBody UserInfo userInfo, HttpServletRequest httpServletRequest){
        Map loginMap =  userInfoService.login(userInfo,httpServletRequest);
        return  Result.ok(loginMap);
    }

    /**
     * 用户退出登录
     * @param token
     * @return
     */
    @GetMapping("/passport/logout")
    public Result logout(@RequestHeader("token") String token){
        userInfoService.logout(token);
        return Result.ok();
    }
}
